const path = require('path');

const express = require('express');
const logger = require('morgan');

const tokenParser = require( 'express-jwt' );

const tokenConfig = require( './config/token.js' );
const customerRouter = require( './routes/customer.js');

const port = 18080 ;
const app = express();

app.use( logger('dev') );
app.use( express.json() );
app.use( express.urlencoded({ extended: false }) );
app.use( express.static(path.join(__dirname, 'public')) );

const tokenMiddleware = tokenParser({ 
    secret: tokenConfig.secret , 
    credentialsRequired: false ,
    algorithms: [ tokenConfig.algorithm ]
}).unless({
    path:['/customer/sign/in']
});

app.use( tokenMiddleware );

app.use( customerRouter );

app.listen( port );